package com.zhijiang.hospital.service.impl;

import com.zhijiang.hospital.mapper.ComEmployeeMapper;
import com.zhijiang.hospital.mapper.HisUserMapper;
import com.zhijiang.hospital.mapper.RoleMapper;
import com.zhijiang.hospital.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 内部方法
 * 实现UserDetailsService   所有的springSecurity方法都经过这里
 */
@Service
public class UserDetilsServiceImpl {


    @Autowired
    UserMapper userMapper;
    @Autowired
    RoleMapper roleMapper;
    @Autowired
    ComEmployeeMapper comEmployeeMapper;
    @Autowired
    HisUserMapper hisUserMapper;
    //@Override
    //public LoginUser loadUserByUsername(String username) throws UsernameNotFoundException {
    //    //获取登录的用户信息
    //    SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username)
    //            .eq(SysUser::getStatus,1));
    //    if (Objects.isNull(sysUser)){
    //        throw new RuntimeException("用户不存在或账号未启用");
    //    }
    //    //SysUser sysUser = hisUserMapper.oneUser(username);
    //    if (Objects.isNull(sysUser)){
    //        throw new RuntimeException("用户不存在或账号未启用");
    //    }
    //    //判断是否是本院员工
    //    ComEmployee comEmployee1 = comEmployeeMapper.findComEmployee(username);
    //    //ComEmployee comEmployee = comEmployeeMapper.selectOne(new LambdaQueryWrapper<ComEmployee>().eq(ComEmployee::getEmplCode, sysUser.getUsername()));
    //    if (Objects.isNull(comEmployee1)||comEmployee1.equals("2")){
    //        throw new RuntimeException("不是本院员工");
    //    }
    //    //if (comEmployee.getValidState().equals("0")){
    //    //    throw new RuntimeException("该账号未启用");
    //    //}
    //
    //    //TODO 根据用户查询权限信息 添加到LoginUser中
    //   List<String> permissions = roleMapper.getRoles("1");
    //    //把数据封装成UserDetails返回
    //    return new LoginUser(sysUser,permissions,comEmployee1);
    //}
}
